package com.leyou.item.controller;

import com.leyou.dto.SpecGroupDTO;
import com.leyou.dto.SpecParamDTO;
import com.leyou.item.service.SpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class SpecController {
    @Autowired
    private SpecService specService;


    @GetMapping("/spec/groups/of/category")
    public ResponseEntity<List<SpecGroupDTO>> queryGroupByCategory(Long id){
        List<SpecGroupDTO> specGroupDTOS = specService.queryGroupByCategory(id);
        return ResponseEntity.ok(specGroupDTOS);
    }

    @GetMapping("/spec/params")
    public ResponseEntity<List<SpecParamDTO>> querySpecParams(
            //可能根据 gid 查询 商品的具体规格
            //也可能根据 cid 查询 搜索页面的用户需要查询的 规格
            @RequestParam(value = "gid",required = false)Long gid,
            @RequestParam(value = "cid",required = false)Long cid,
            @RequestParam(value = "searching",required = false)Boolean searching
    ){
        return ResponseEntity.ok(specService.querySpecParams(gid, cid, searching));
    }


    @GetMapping("/spec/groups/of/category/params")
    public ResponseEntity<List<SpecGroupDTO>> findSpecGroupWithParamsBuCid(@RequestParam("id") Long id ){
        List<SpecGroupDTO> list =  specService.findSpecGroupWithParamsBuCid(id);
        return ResponseEntity.ok(list);
    }

}
